/**
 *
 */
package com.wedroid.api.mapper;

import com.wedroid.api.handler.ResourceHandler;
import com.wedroid.entity.contact.Contacter;
import com.wedroid.entity.contact.ContacterType;
import com.wedroid.entity.contact.GroupMember;

/**
 * @author lute
 */
public class ContacterMapper {

    private String nickName;

    private String remarkName;

    private String displayName;

    private String headImgUrl;

    private int memberCount;

    private ContacterType type;

    /**
     * @param contacter
     */
    public ContacterMapper(Contacter contacter) {
        if (contacter == null || contacter.getProfile() == null) {
            throw new IllegalArgumentException("Empty contacter or contacter profile");
        }
        this.nickName = contacter.getProfile().getNickName();
        this.remarkName = contacter.getProfile().getRemarkName();
        this.displayName = contacter.getProfile().getDisplayName();
        this.headImgUrl = contacter.getProfile().getHeadImgUrl();
        this.memberCount = contacter.getProfile().getMemberCount();
        this.type = contacter.getContacterTypeEnum();
    }

    /**
     * @param groupMember
     */
    public ContacterMapper(GroupMember groupMember) {
        if (groupMember == null || groupMember.getProfile() == null) {
            throw new IllegalArgumentException("Empty group member or group member profile");
        }
        this.nickName = groupMember.getProfile().getNickName();
        this.remarkName = groupMember.getProfile().getRemarkName();
        this.displayName = groupMember.getProfile().getDisplayName();
        this.headImgUrl = groupMember.getProfile().getHeadImgUrl();
        this.memberCount = groupMember.getProfile().getMemberCount();
        this.type = ContacterType.GROUP_MEMBER;
    }

    /**
     * @return
     */
    public int getContacterTypeCode() {
        return type.getCode();
    }

    /**
     * @param handler
     * @return
     */
    public ContacterMapper resolveUrl(ResourceHandler handler) {
        this.headImgUrl = handler.resolveResourceUrl(this.headImgUrl);
        return this;
    }

    /**
     * @return the nickName
     */
    public String getNickName() {
        return nickName;
    }

    /**
     * @return the remarkName
     */
    public String getRemarkName() {
        return remarkName;
    }

    /**
     * @return the displayName
     */
    public String getDisplayName() {
        return displayName;
    }

    /**
     * @return the headImgUrl
     */
    public String getHeadImgUrl() {
        return headImgUrl;
    }

    /**
     * @return the memberCount
     */
    public int getMemberCount() {
        return memberCount;
    }

    /**
     * @return the type
     */
    public ContacterType getType() {
        return type;
    }

}
